<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--{include file='comm/header.tpl'}-->
    <title>商品规格组</title>
</head>

<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_crub">
        <span class="now_crub" style="margin-left:12px;">商品规格组</span>
    </div>

    <div class="comm_content">

        <div class="search-box">
            <div style="position:relative">
                <form id="search_form" onsubmit="return false;">
                    <table>
                        <tbody>
                            <tr>
                                <td height="27px">
                                    <span>规格组名称：<input type="text" name="specGroupName" value="" /></span>
                                    <span><input type="button" value="查询" class="btn" onclick="specGroup.search();" /></span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>

        <table id="flex" style="display:none"></table>

    </div>

</div>

<div id="pop" style="display: none;">

    <div style="width:100%; background: #ffffff">
        <form id = "specGroup_form" onsubmit="return false;">
            <div class="input-group input-group-lg"  >
                <span class="input-group-addon">规格组名称：</span>
                <input class="form-control"  type="text" id="specGroupName" name="specGroupName" maxlength="20" placeholder="请输入规格组名称 【必填项】"  value="" />
            </div>

            <div class="input-group input-group-lg"  >
                <span class="input-group-addon">排列序号：</span>
                <input class="form-control"  type="text" id="sortOrder" name="sortOrder" maxlength="20" placeholder="请输入排列序号 【必填项】"  />
            </div>

            <div class="input-group input-group-lg" >
                <span class="input-group-addon">一级规格：</span>
                <span class="input-group-radio">
                    <input type="radio" name="isColor" value="1" > 是&nbsp;&nbsp;
                    <input type="radio" name="isColor"   value="0"  checked="" > 否
                </span>
            </div>

            <input type="hidden" name="useFlg" id="useFlg" value= "1" />
            <input type="hidden" name="specGroupID" id="specGroupID" value= "" />
        </form>
    </div>
</div>

<script type="text/javascript">
$("#flex").flexigrid({
    url:"/invokingAjax-backend/goods/specGroup.ajax?operFlg=1&xjx=none",
    dataType: "json",
    colModel : [
        <!--{if $edit_permission}-->
            {display: "操作", width : 100, align: "center"},
            <!--{/if}-->
            {display: "规格组号", name : "specGroupID", width : 100, sortable : true},
            {display: "规格组名称", width : 280},
            {display: "排列序号", width : 100},
            {display: "一级规格",width : 100, align : "center"},
            {display: "使用状态",width :100, align : "center"}
        ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "specGroup.edit"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "specGroup.deleteSpecGroup"}
        ],
        <!--{/if}-->
        sortname: "specGroupID",
        sortorder: "asc",
        usepager: true,
        rp: 10,
        useRp: true,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    var specGroup = {

        delete_str: "" ,
		useFlg_str : "" ,
        dt:"",
		
        //搜索规格组
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt}).flexReload();
        },

        change: {

            specGroupID: "",
            useFlg: "",

            confirm: function(specGroupID,useFlg) {
                this.specGroupID = specGroupID;
                this.useFlg = useFlg;
                if (useFlg == 0) {
                    E.confirm("您确认要禁用该商品规格组吗？", "specGroup.change.execute");
                } else {
                    specGroup.change.execute();
                }
            },

            execute: function() {
               	E.loadding.open("请稍候...");
                 
                E.ajax_get({
                    url: "/invokingAjax-backend/goods/specGroup.ajax?operFlg=7",
                    data: {
                        specGroupID: this.specGroupID,
                        useFlg: this.useFlg
                    },
                    call: "specGroup.change.result"
                });
            },

            result: function( o ) {
                E.loadding.close();
                if (o.code == 200) {
                    specGroup.load();
                    E.alert(o.message, 2);
                } else {
                    E.alert(o.message);
                }
            }

        },

        deleteSpecGroup: function() {
            this.delete_str = "";
            $.each($("#flex").find("tr"), function(k, v) {
                if ($(v).hasClass("trSelected")) {
                    specGroup.delete_str += "_" + $(v).attr("id").replace("row", "");
                }
            });

            if (this.delete_str == "")
                E.alert("请选择需要删除的商品规格组");
            else
                E.confirm("您确认要删除选中的规格组吗?", "specGroup.deleteConfirm");
        },
       
        deleteConfirm: function() {
            this.delete_str = this.delete_str.substr(1);
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/specGroup.ajax?operFlg=4&delete_str=" + specGroup.delete_str,
                dataType: "JSON",
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.alert(result_obj.message, 2, "specGroup.load");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //编辑或添加规格组
        edit: function(specGroupID){
            E.loadding.open();
            var name = "";
            if(specGroupID){
                name = "修改规格组";
                E.ajax_post({
                    url: "/invokingAjax-backend/goods/specGroup.ajax?operFlg=5&xjx=none",
                    data:{specGroupID:specGroupID},
                    call: "specGroup.specGroupEdit"
                });
            }else{
                name = "添加规格组";
                E.ajax_get({
                    url:"/invokingAjax-backend/goods/specGroup.ajax?operFlg=6",
                    data:"" ,
                    call:"specGroup.sortUp"
                });
            }

            E.popup.open({
                id:"pop",
                title: name,
                content: "",
                css: "width:960px;",
                btnName: "保存",
                btnCall:"specGroup.check();" //
            });


        },

        specGroupEdit: function(o) {

            E.loadding.close();
            $("#specGroupName").val(o.specGroupName);
            $("#sortOrder").val(o.sortOrder);
            $("#specGroupID").val(o.specGroupID);
            $("#useFlg").val(o.useFlg);
            $("input[name='isColor'][value='"+ o.isColor+"']").attr("checked",true);
        },

        check: function() {
            this.dt = E.getFormValues("specGroup_form");
            var error_msg = "";
            if (this.dt.specGroupName == "")
                error_msg += "规格组名称不能为空<br />";

            if (!E.isInt(this.dt.sortOrder))
                error_msg += "排序序号必须为数字<br />";

            if (error_msg != "")
                E.alert(error_msg);
            else
                specGroup.addSave() ;
        },

        //保存规格组信息
        addSave: function() {
            this.dt = E.getFormValues("specGroup_form");
            var id = this.dt.specGroupID;
            var sort = this.dt.sortOrder;
            sort++;

            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/goods/specGroup.ajax?operFlg=2" ,
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        specGroup.load();
                        if(id){
                            E.alert(result_obj.message, 2, "E.popup.close");
                        }else{
                            $("#sortOrder").val(sort);
                            E.alert(result_obj.message, 2, "specGroup.reset");
                        }
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        reset: function(){

            $("#specGroupName").val("");
            $("input[name='isColor'][value='0']").attr("checked",true);
        },

        //最大序列号
        sortUp: function(o){
        	E.loadding.close();
            $("#sortOrder").val(o.sortOrder);
        },
        load: function() {
            $("#flex").flexReload();
        }

    };
</script>
</body>
</html>